  package 基础语法;

import java.util.StringJoiner;

public class StringJoinerLearn {
    public static void main(String[] args) {
      //其构造函数所需的CharSequence是一个接口，String、StringBuilder是其一个实现类，按ctrl+右击类名可以跳转到源码，选中源码类名，右击可以看到“转到实现”选项，可以看到岂有很多实现
        StringJoiner joiner=new StringJoiner("-","begin",new StringBuilder().append("end"));//指定凭借时的间隔符合，开始、结束符合
        joiner.add("[").add("asas").add("]");
        System.out.println(joiner);
         StringJoiner joiner2=new StringJoiner(new MyString());//分隔符
         joiner2.add("aa").add("bb");
         System.out.println(joiner2);
    }

    
}
class MyString implements CharSequence{

  @Override
  public int length() {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'length'");
  }

  @Override
  public char charAt(int index) {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'charAt'");
  }

  @Override
  public CharSequence subSequence(int start, int end) {
    // TODO Auto-generated method stub
    throw new UnsupportedOperationException("Unimplemented method 'subSequence'");
  }
  @Override
  public String  toString(){
    return "-myString-";
  }
  
}